package app.modules.infrastructure.profile.util.conversion;

import app.modules.common.annotation.ConvertFrom;
import app.modules.common.annotation.ConvertTo;
import app.modules.infrastructure.profile.dto.web.WebProfileItemDTO;
import app.modules.infrastructure.profile.persistence.entity.ProfileItemEO;
import cn.hutool.core.collection.CollectionUtil;
import jasmine.framework.common.util.MapperUtil;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author mh.z
 */
public class ProfileItemConvertUtil {

    @ConvertFrom(ProfileItemEO.class)
    @ConvertTo(WebProfileItemDTO.class)
    public static List<WebProfileItemDTO> profileItemEO2WebProfileItemDTO(Collection<ProfileItemEO> records) {
        if (CollectionUtil.isEmpty(records)) {
            return Collections.emptyList();
        }

        return MapperUtil.mapToList(records, WebProfileItemDTO.class);
    }

    @ConvertFrom(ProfileItemEO.class)
    @ConvertTo(WebProfileItemDTO.class)
    public static WebProfileItemDTO profileItemEO2WebProfileItemDTO(ProfileItemEO record) {
        if (record == null) {
            return null;
        }

        return MapperUtil.mapTo(record, WebProfileItemDTO.class);
    }

}
